<template>
	<view class="content">
		<view class="top-default-box" @click="getMyAddressInfo(1)">
			<text>获取微信添加地址</text>
		</view>
		<block v-if="userList.length>0">
			<view class="my-address-item-box" v-for="(item,index) in userList" :key="item.address_id" @click="goUrls(item.address_id)">
				<view class="user-name-phone-box">
					<text>{{item.real_name}}</text>
					<text class="phone">{{item.phone}}</text>
					<text class="default" v-if="item.is_default==1">默认</text>
				</view>
				<view class="user-address-box">
					<view>{{`${item.province}${item.city}${item.district}${item.detail}`}}</view>
					<view class="flex-c-c" @click.stop="goUrl(item.address_id)"><image src="../static/icon6.png" mode=""></image></view>
				</view>
			</view>
		</block>
		<!-- 无记录状态 -->
		<block v-else>
			<icon-status :imgUrl="'../../pageMember/static/icon5.png'" :statusInfo="'你还没有添加地址'"></icon-status>
		</block>
		<view class="bottom-plate-box">
			<!-- 底部but -->
			<view class="bottom-but-box" @click="goUrl(0)">
				<text>添加地址</text>
			</view>
		</view>
	</view>
</template>

<script>
	import iconStatus from '@/components/noRecordIcon/iconStatus.vue';
	export default {
		components:{
			iconStatus
		},
		data(){
			return {
				userList:[],//用户地址列表
				status:0,//状态
			}
		},
		onLoad(options) {
			uni.showLoading({title:"加载中"});
			this.status = Number(options.status);
		},
		onShow() {
			this.getMyAddress();
		},
		methods:{
			getMyAddress(){ //获取我的收货地址
				this.$u.api.userAddressApi({}).then(res=>{
					if(res.code==1){
						console.log('我的地址：',res.data);
						this.userList = res.data;
					}
				});
			},
			getMyAddressInfo(status){ //获取我的微信地址信息
				this.$gourl('./addAddress?isOk='+status);
			},
			goUrl(addressId){
				this.$gourl('./addAddress?status='+addressId);
			},
			goUrls(addressId){ //选中设置为默认地址
				if(this.status){
					this.$u.api.setDefaultAddApi({address_id:addressId}).then(res=>{
						if(res.code==1){
							console.log('设置默认：',res);
							uni.navigateBack({});
						}
					});
				}else{
					return;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		width: 100%;
		height: calc(100vh - 150rpx);
		overflow: hidden;overflow-y: auto;
		font-family: Microsoft YaHei;
		box-sizing: border-box;
		padding: 20rpx;
		.top-default-box{
			width: 100%;
			border: 1rpx solid #000;
			padding: 30rpx 0;
			text-align: center;
			font-size: 30rpx;font-weight: bold;color: #333333;
			border-radius: 10rpx;
		}
		.my-address-item-box{
			padding: 40rpx 0;
			border-bottom: 1rpx solid #eee;
			.user-name-phone-box{
				font-size: 30rpx;
				font-weight: bold;
				color: #333333;
				margin-bottom: 30rpx;
				.phone{font-size: 24rpx;font-weight: 400;color: #999999;margin-left: 20rpx;}
				.default{
					display: inline-block;
					width: 80rpx;
					height: 30rpx;
					background: #FF5C5C;
					border-radius: 15rpx;
					font-size: 22rpx !important;
					text-align: center;
					font-weight: 400;
					color: #FFFFFF !important;
					margin-left: 20rpx;
				}
			}
			.user-address-box{
				font-size: 26rpx;
				font-weight: 400;
				color: #333333;
				display: flex;
				view:first-child{flex: 0.9;}
				view:last-child{
					flex: 0.1;
					justify-content: flex-end;
					margin-right: 0;
					line-height: 0;
					image{width: 30rpx; height: 30rpx;}
				}
			}
		}
		.bottom-plate-box{
			position: fixed;bottom: 0;left: 0;right: 0;
			z-index: 100;
			width: 100%;
			padding: 30rpx 20rpx;
			padding-bottom: 50rpx;
			background: #fff;
		.bottom-but-box{
			padding: 25rpx 0;
			background: #000;
			font-size: 30rpx;
			font-weight: 400;
			color: #FFFFFF;
			text-align: center;
			border-radius: 50rpx;
			}
		}
	}
</style>